﻿Imports System.Data
Imports System.Data.SqlClient
Imports Entidad

Public Class DocumentoClienteDetallePickeadorDatos

    Sub ingresarPedidoDetallePickeador(ByVal pdp As PedidoDetallePickeador, cia As String, suc As String, tipoDOC As String)
        Dim conex As New Conexion
        Dim coneccion As SqlConnection = conex.conectar()
        coneccion.Open()
        Dim query As String = "INSERT INTO Documento_Cliente_Detalle_Pickeador(CIA, " &
                              "SUC_Codigo,ALM_Codigo,TDOC_Codigo,DCI_Codigo,DCD_Codigo, " &
                              "DCP_Codigo,PICK_Codigo,DCDP_Cantidad, " &
                              "DCDP_FechaAsignacion,DCDP_FechaInicio, " &
                              "DCDP_FechaFin,EST_Codigo,DCDP_CantPick, " &
                              "DCDP_Asig_Act,DCDP_Activo) " &
                              "VALUES(@cia,@suc,'00',@tipo,@dciCodigo,@dcdCodigo, " &
                              "@ppCodigo,@pickCodigo,@pdpCantidad, " &
                              "getDate(),null,null,'15','0','0','1')"
        Dim comando As New SqlCommand
        With comando
            .Connection = coneccion
            .CommandText = query
            .Parameters.AddWithValue("@cia", cia)
            .Parameters.AddWithValue("@suc", suc)
            .Parameters.AddWithValue("@tipo", tipoDOC)
            .Parameters.AddWithValue("@dciCodigo", pdp.PED_Codigo)
            .Parameters.AddWithValue("@dcdCodigo", pdp.PDD_Codigo)
            .Parameters.AddWithValue("@ppCodigo", pdp.PP_Codigo)
            .Parameters.AddWithValue("@pickCodigo", pdp.PICK_Codigo)
            .Parameters.AddWithValue("@pdpCantidad", pdp.PDP_Cantidad)
            .ExecuteNonQuery()
        End With
        coneccion.Close()
    End Sub

    Sub eliminarPedidoPickeador(ByVal pedCodigo As String, ByVal pddCodigo As String, ByVal pickCodigo As String, tipoDOC As String)
        Dim conex As New Conexion
        Dim coneccion As SqlConnection = conex.conectar()
        coneccion.Open()
        Dim query As String = "UPDATE Documento_Cliente_Detalle_Pickeador " &
                              "SET DCDP_Activo = '0' " &
                              "WHERE DCI_Codigo = @dciCodigo " &
                              "AND TDOC_Codigo = @tipo " &
                              "AND DCD_Codigo = @dcdCodigo " &
                              "AND PICK_Codigo = @pickCodigo " &
                              "AND  DCDP_Activo = '1'"

        Dim comando As New SqlCommand
        With comando
            .Connection = coneccion
            .CommandText = query
            .Parameters.AddWithValue("@dciCodigo", pedCodigo)
            .Parameters.AddWithValue("@tipo", tipoDOC)
            .Parameters.AddWithValue("@dcdCodigo", pddCodigo)
            .Parameters.AddWithValue("@pickCodigo", pickCodigo)
            .ExecuteNonQuery()
        End With
        coneccion.Close()
    End Sub

End Class
